<template>
    <div>
        <van-field v-model="form.name" label='名字'/>
        选择课程：
        <select v-model="form.course_id">
            <option :value='i.id' v-for="i in course">{{i.title}}</option>
        </select><br>
        上传视频：<van-uploader :after-read='vedio_upload' />
        <video-player class="video-player vjs-custom-skin"
                            ref="videoPlayer"
                            :playsinline="true"
                            :options="form.vedio_url">
         </video-player>
        <van-button @click="add" color="linear-gradient(to right, #ff6034,#7232dd)">添加</van-button>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                course:[],
                form:{'vedio_url':''}
            }
        },
        methods:{
            get_course(){
                this.$axios.get('courseM').then(res=>{
                    this.course = res.data.list
                })
            },
            vedio_upload(file){
                if(this.form.course_id){
                    let formdata = new FormData
                    formdata.append('file',file.file)
                    formdata.append('course_id',this.form.course_id)
                    this.$axios.post('vedioupload',formdata).then(res=>{
                        this.form.vedio_url = res.data.url
                    })
                }else{
                    alert('请选择课程在上传视频')
                }
            },
            add(){
                this.$axios.post('jieM',this.form).then(res=>{
                    alert('添加成功')
                })
            }
        },
        mounted(){
            this.get_course()
        }
    }
</script>

<style scoped>

</style>